package com.qfedu.service.impl;

import com.qfedu.dao.ProductDao;
import com.qfedu.dao.impl.ProductDaoImpl;
import com.qfedu.entity.PageBean;
import com.qfedu.entity.Product;
import com.qfedu.service.ProductService;
import com.qfedu.utils.BaseDao;

import java.sql.SQLException;
import java.util.List;

public class ProductServiceImpl implements ProductService {
    private ProductDao productDao = new ProductDaoImpl();
    @Override
    public PageBean<Product> getPageBean(int tid, int currentPage, int pageSize) throws SQLException {
        List<Product> productList = productDao.getProductByTypeAndPage(tid, currentPage, pageSize);
        int totalCount = productDao.getProductByTypeCount(tid);
        PageBean<Product> productPageBean = new PageBean<>(productList, currentPage, pageSize, totalCount);
        return productPageBean;
    }

    @Override
    public Product getProductById(int pid) throws SQLException {
        return productDao.getProductById(pid);
    }
}
